//
//  CTAppInitFile.m
//  ConstellationTalk_0.1
//
//  Created by riley on 15/4/22.
//  Copyright (c) 2015年 riley chu. All rights reserved.
//

#import "CTAppInitFile.h"
#import "AppDelegate.h"
#import "CTDebugManager.h"
#import "CTConfig.h"
#import "CTAppInfo.h"

#import <ShareSDK/ShareSDK.h>
#import "WXApi.h"
#import "WeiboSDK.h"
#import <TencentOpenAPI/QQApi.h>
#import <TencentOpenAPI/QQApiInterface.h>
#import <TencentOpenAPI/TencentOAuth.h>
#import "MobClick.h"
#import "APService.h"

#import <SMS_SDK/SMS_SDK.h>
#import "CTLogin.h"
#import "CTFile.h"
#import "CTTabBarController.h"

////test vc
#import "CTRegisterViewController.h"
#import "CTFollowUserViewController.h"

static CTTabBarController * tabbarVC = nil;


@implementation CTAppInitFile

+(void)initEvent:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
withAppDelegate:(AppDelegate *)delegate
{
    
    /* ==================== debug log show ==================== */
   
#ifdef CT_CONFIG_DEBUG
    [CTDebugManager setIsDebug:YES];
#else
    [CTDebugManager setIsDebug:NO];
#endif
    

    
    
    /* ==================== 第三方分享注册 ==================== */
#ifdef CT_CONFIG_REGISTER_CHINA
    [ShareSDK ssoEnabled:NO];
    [ShareSDK registerApp:@"2f014f2b24f0"];
    
    //短信验证注册
    [SMS_SDK registerApp:@"2f005295272a" withSecret:@"34c83df916bd3d2bab31f96d152b3c74"];
 
#else
    [ShareSDK ssoEnabled:NO];
    [ShareSDK registerApp:@"674da64a2464"];
    
    //短信验证注册
  //  [SMS_SDK registerApp:@"674da64a2464" withSecret:@"370d708c60263b12280e5bc4968db211"];
#endif
    
    //  连接新浪微博开放平台
    [ShareSDK connectSinaWeiboWithAppKey:@"2077116271"
                               appSecret:@"c32ab972d75d50f043330211e3dd5573"
                             redirectUri:@"https://api.weibo.com/oauth2/default.html"];
    
    [ShareSDK connectWeChatWithAppId:@"wx5731c1ffd2542eb8"
                           appSecret:@"84ae9d4d1f5a1504b75d11f4f1534ab8"
                           wechatCls:[WXApi class]];
    
    
    //添加QQ空间应用  注册网址  http://connect.qq.com/intro/login/
    [ShareSDK connectQZoneWithAppKey:@"1104737458"//@"1103420373"
                           appSecret:@"3XvYR00TS1NGtIBc"//@"20EDJGwzt9xHMHLk"
                   qqApiInterfaceCls:[QQApiInterface class]
                     tencentOAuthCls:[TencentOAuth class]];
    
    //连接QQ应用以使用相关功能，此应用需要引用QQCQQonnection.framework和QQApi.framework库
    [ShareSDK connectQQWithAppId:@"QQ41D8F4B2" qqApiCls:[QQApi class]];
    
    
    
    
    
    /* ==================== UMSDK统计 Register ==================== */
    #ifdef CT_CONFIG_DEBUG
        //debug模式
        [MobClick startWithAppkey:@"559b36c467e58eb35b002302" reportPolicy:REALTIME   channelId:nil];
    #else
        //release模式
        [MobClick startWithAppkey:@"559b36c467e58eb35b002302" reportPolicy:BATCH   channelId:nil];
    #endif
        [MobClick setCrashReportEnabled:YES];
        [MobClick setAppVersion:[CTAppInfo appVersion]];
    
    
    
    /* ==================== J_Push Register ==================== */
        [APService setupWithOption:launchOptions];
        
        // Required
    #if __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_7_1
        if ([[UIDevice currentDevice].systemVersion floatValue] >= 8.0) {
            //categories
            [APService
             registerForRemoteNotificationTypes:(UIUserNotificationTypeBadge |
                                                 UIUserNotificationTypeSound |
                                                 UIUserNotificationTypeAlert)
             categories:nil];
        } else {
            //categories nil
            [APService
             registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |UIRemoteNotificationTypeSound |
                                                 UIRemoteNotificationTypeAlert)
    #else
             //categories nil
             categories:nil];
            [APService
             registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |
                                                 UIRemoteNotificationTypeSound |
                                                 UIRemoteNotificationTypeAlert)
    #endif
             // Required
             categories:nil];
        }
    
   
    
    
    /* ==================== 是否是第一次登陆新版本app ==================== */
    if ([CTLogin isAppLicationFirstLunch] == YES)
    {
        //第一次登陆
        
        //移除版本信息appVersion.plist文件
        [CTFile removeFile:@"appVersionInfo.plist" fromDoc:CTFileDocDocuments fromPath:@"appVersion"];
        
        
        [CTFile removeFile:@"switch.text" fromDoc:CTFileDocDocuments fromPath:@"switch"];
       
    }
    else
    {
        
    }
    
    
    
    
    /* ==================== 初始化root vc ==================== */
    [self initRootController:delegate];
    
}




#pragma mark root初始化
+(void)initRootController:(AppDelegate *)delegate
{
//    UICollectionView
//    CTRegisterViewController * vc = [[CTRegisterViewController alloc] init];
////    CTFollowUserViewController *vc = [[CTFollowUserViewController alloc]init];
//    delegate.window.rootViewController = vc;
    
    
    CTTabBarController * tabBarVC = [[CTTabBarController alloc] init];
    delegate.window.rootViewController = tabBarVC;
    
    tabbarVC = tabBarVC;
}

+(CTTabBarController *)rootTabbar
{
    return tabbarVC;
}

@end
